package nc.ui.jmcg.zjqd.inventory;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;

public class PoiUtils {
	
	public static String getCellValueOfString(HSSFCell cell){
		String result = null;
		if(cell != null){
			HSSFRichTextString value = cell.getRichStringCellValue();
			if(value != null){
				result = value.toString();
			}
		}
		return result;
	}
	
	public static UFDouble getCellValueOfDouble(HSSFCell cell){
		UFDouble result = null;
		if(cell != null){
			double value = cell.getNumericCellValue();
			result = new UFDouble(value);
		}
		return result;
	}
	
	public static Integer getCellValueOfInteger(HSSFCell cell){
		Integer result = null;
		if(cell != null){
			double value = cell.getNumericCellValue();
			result = Double.valueOf(value).intValue();
		}
		return result;
	}
	
	public static UFDate getCellValueOfDate(HSSFCell cell){
		UFDate result = null;
		if(cell != null){
			double value = cell.getNumericCellValue();
			if(value != (double)0){
				result = new UFDate(HSSFDateUtil.getJavaDate(value));
			}
		}
		return result;
	}
	
	public static Date StringToDate(String dateStr,String formatStr){
		DateFormat sdf=new SimpleDateFormat(formatStr);
		Date date=null;
		try {
		   date = sdf.parse(dateStr);
		} catch (ParseException e) {
		   e.printStackTrace();
		}
		return date;
	}

}
